<template>
	<view>
		<view class="listBox">
			<view class="item" v-for="(dt,index) in list" :key="dt.external_contact.external_userid" @click="getDetail(dt)">
				<view class="hearderImg">
					<image class="imgbox" :src="dt.external_contact.avatar" mode="aspectFill"/>
				</view>
				<view class="name">
					{{dt.external_contact.name}} 
					<text class="st">[{{dt.follow_info.state}}]</text>
				</view>
			</view>
		</view>
		<button type="default" @click="getEwm">获取扫描加入二维码</button>
		<button type="default" @click="getUserList">获取客户列表</button>
		<button type="default" @click="doCreateMeeting">创建预约会议</button>
		<button type="default" @click="doSendMessage">消息推送</button>
		<button type="default" @click="createFriendsCircle">创建朋友圈消息</button>
		<button type="default" @click="getMeetingDetail">获取会议详情</button>
		<button type="default" @click="getTagList">获取客户标签列表</button>
		<button type="default" @click="createTag">在'企业'标签组下创建标签</button>
		<button type="default" @click="createTag2">创建标签组及标签</button>
		<!-- <empty/> -->
	</view>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import Request from "@/utils/http.js"
	import {
		getAccessToken,
		getJoinQrCode,
		getUserid,
		getCustomList,
		getCustomDetail,
		createMeeting,
		getMeetingDetail,
		sendMessage,
		createMessageToFriendsCircle,
		getCustomTagList,
		addTag
	} from '@/api/qy-wechat-api.js'
	import {setStorage} from '@/utils/common.js'
	import empty from "@/components/empty"
	export default defineComponent({
		components:{
			empty
		},
		props:{
		
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				msg:'123459',
				userName:computed(()=>store.state.base.userName),
				imgUrlPrefix:getApp().globalData.imgUrlPrefix,
				list:'',
				userId:''
			})
			
			onLoad((options)=>{
				
			})
			
			onShow(()=>{
				
			})

			onMounted(async ()=>{
				setTimeout(()=>{
					//state.msg = '78999'
					store.commit('base/set_userName','yuss')
				},2000)
				
			})
			
			const getEwm = async ()=>{
				if(!state.userId){
					const res = await getUserid({mobile:'18723497924'})
					state.userId = res.data.userid
				}
				getJoinQrCode({userid:state.userId,state:"yu789"}) 
			}
			
			const getUserList = async ()=>{
			
				if(!state.userId){
					const res = await getUserid({mobile:'18723497924'})
					state.userId = res.data.userid
				}
				
				// 获取客户列表
				const res2 = await getCustomList({
					userid:state.userId,
					limit:10
				})
				state.list = res2.data.external_contact_list
			}
			
			const getDetail = (item)=>{
				console.log("GGG:",item)
				getCustomDetail({external_userid:item.external_contact.external_userid})
			}
			const doCreateMeeting = async ()=>{
				const res = await createMeeting({
					admin_userid:state.userId,// 会议管理员userid
					title:'测试会议6', // 会议的标题，最多支持40个字节或者20个utf8字符
					meeting_start:'1694772000', // 会议开始时间的unix时间戳。需大于当前时间
					meeting_duration:3600, // 会议持续时间单位秒，最小300秒
					invitees:{ // 会议参与人员（必须包括管理者）
						userid: [state.userId]
					}
				})
				
			}
			const doSendMessage = async ()=>{
				const content = `测试消息推送\n主题：测试会议6\n会议时间：2023/09/15 18:00-19:00\n会议链接：https://work.weixin.qq.com/webapp/tm/PSeUt9WoNucJSA0pSejOua`
				const res = await sendMessage({
					touser:`${state.userId}|PengQiYang`, // 指定接收消息的成员，成员ID列表（多个接收者用‘|’分隔，最多支持1000个）"UserID1|UserID2|UserID3"
					msgtype:'text',
					content
				})
			}
			
			// 创建朋友圈消息（这里创建之后，企业员工就可以在企业微信里面收到提示，按提示确认发送，就可以把消息发到朋友圈，对应的客户就能看得到）
			const createFriendsCircle =  async()=>{
				const res = await createMessageToFriendsCircle({
					"text": {
						"content": "朋友圈文本消息内容"
					},
				})
			}
			
			const getMeetingDetail = ()=>{
				getMeetingDetail({meetingid: "hyy8p1VAAASPBkZ8ag6FY5_q7P1mAIQQ"})
			}
			
			const getTagList = async()=>{
				getCustomTagList()
			}
			
			const createTag = async()=>{
				addTag({
					group_id: "ety8p1VAAAnWanp4c2d5bMTSU8HD8cvw",
					tag:[{name:'58同城'}]
				})
			}
			const createTag2 = async()=>{
				addTag({
					group_name: "易见财税",
					tag:[{name:'一般'}]
				})
			}
			
			return {
				...toRefs(state),
				getDetail,
				doCreateMeeting,
				doSendMessage,
				createFriendsCircle,
				getTagList,
				createTag,
				createTag2,
				getMeetingDetail,
				getUserList,
				getEwm
			}
		}
	})
</script>

<style lang="scss" scoped>
	.listBox{
		padding: 0;
		margin: 0;
		width: 100%;
		.item{
			display: flex;
			padding: 20rpx;
			.hearderImg{
				width: 100rpx;
				height: 100rpx;
				overflow: hidden;
				border-radius: 50%;
				.imgbox{
					display: block;
					width: 100%;
					height: 100%;
				}
			}
			.name{
				display: flex;
				font-size: 30rpx;
				justify-content: center; 
				align-items: center;
				.st{
					color: red;
				}
			}
		}
	}
</style>
